# _*_ coding : utf-8 _*_
# @Time : 2023/12/5 21:25
# @Author : 韩宗森
# @File : 12_异常捕获
# @Project : pythonProject


import urllib.request
import urllib.error

# url = 'https://blog.csdn.net/2301_76474805/article/details/130639920'
url = 'https://www.gougandasdfsa111.com'

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36'
}

try:
    # 请求对象的定制
    request = urllib.request.Request(url=url, headers=headers)

    # 模拟浏览器向服务器发送请求
    response = urllib.request.urlopen(request)

    # 获取响应的内容
    content = response.read().decode('utf-8')

    # 打印数据
    print(content)

except urllib.error.HTTPError:
    print('HTTPError请求有误...')
except urllib.error.URLError:
    print('地址有误URLError...')
